package cube.net.frame;

/**
 * 具有标识的帧 这样的帧可以像链条一样组合在一起 <br>
 * 然后可以由<code>FrameSelector</code>通过标识进行选择
 * 
 * @author abiao
 */
public abstract class IdentityFrame implements Frame, Cloneable {

    /**
     * 帧标识
     */
    private Identity frameIdentity;

    /**
     * 下一帧
     */
    private IdentityFrame next;

    /**
     * 设置下一帧
     */
    public void setNext(IdentityFrame next) {
        this.next = next;
    }

    /**
     * 按标识获取帧
     */
    public IdentityFrame get(Identity identity) {
        if (frameIdentity.equals(identity)) {
            return this;
        }
        return next == null ? null : next.get(identity);
    }

    /**
     * @return the frameIdentity
     */
    public Identity getFrameIdentity() {
        return frameIdentity;
    }

    /**
     * @param frameIdentity the frameIdentity to set
     */
    public void setFrameIdentity(Identity frameIdentity) {
        this.frameIdentity = frameIdentity;
    }

    /**
     * self clone
     */
    public IdentityFrame clone() {
        IdentityFrame identityFrame = null;
        try {
            identityFrame = (IdentityFrame) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return identityFrame;
    }
}
